#include "QFont.h"
//#include "QOsBase.h"

EXPORT_C CQFont::CQFont(QVOID* pFont, QINT32 nFontType)
{
	QINT nFontSize = 12;
	cxFont = cx_font_create(pFont,nFontSize,nFontType);
	//m_pFont = pFont;
	m_nFontType = nFontType;
}

EXPORT_C CQFont::~CQFont()
{
	cx_font_destroy(&cxFont);
	//sanford 100522
	cxFont.handle = QNULL;
}


// EXPORT_C QBOOL CQFont::ResetFont(QVOID* pFont)
// {
// 	QINT nFontSize = 12;
// 	QINT nFontType = 0;
// 	cxFont = cx_font_create(pFont,nFontSize,nFontType);
// 	return QTRUE;
// }

EXPORT_C QINT32 CQFont::CharWidthInPixels(QUINT16 wChar) const
{
	CQWString s;
	s.Empty();
	s.AppendChar(wChar);
	return cx_font_stringwidth(cxFont,(QSHORT*)s.GetDataPtr());
	//return cx_font_characterwidth(cxFont,wChar);
}

EXPORT_C QINT32 CQFont::TextWidthInPixels(const CQWString&  aText) const
{
	return cx_font_stringwidth(cxFont,(QSHORT*)aText.GetDataPtr());
}

EXPORT_C QINT32 CQFont::TextWidthInPixels(LPCWSTR aText,int alength) const
{
	return cx_font_stringwidth(cxFont,(QSHORT*)aText);
}

EXPORT_C QINT32 CQFont::TextWidthInPixels(const CQSString & aString) const
{
	if( aString.GetLength() <= 0 ) 
	{
		return 0 ;
	}

	return TextWidthInPixels(CQWString(aString));
}

EXPORT_C QINT32 CQFont::HeightInPixels() const
{
    return cx_font_height_in_pixels(cxFont);
}

EXPORT_C QINT32 CQFont::AscentInPixels() const
{
	return HeightInPixels();
}